package org.ling.xuan.customnew;

import cn.hutool.core.util.StrUtil;
import com.intellij.lang.Language;
import org.ling.xuan.customnew.pannel.UpdXmlPanel;
import org.ling.xuan.dao.FileDao;
import org.ling.xuan.dao.LocalAddDao;
import org.ling.xuan.entity.mo.CommonSetting;
import org.ling.xuan.entity.mo.LocalAdd;

import java.awt.*;
import java.util.Optional;

public class UpdBeforeTemplate implements HundSunFileTemplate{
    private UpdXmlPanel updXmlPanel;

    public UpdBeforeTemplate() {
        LocalAdd localAdd = LocalAddDao.getCur();
        CommonSetting commonSetting = FileDao.getCommonSetting();
        updXmlPanel = new UpdXmlPanel(commonSetting,localAdd,"xml","-upd");
    }

    @Override
    public String getFileName() {
        return Optional.of(updXmlPanel.fileNameField.getText()).orElse("");
    }

    @Override
    public String getContent() {
        String ex = "<root>\n" +
                "    <lx-modifiy modNo=\"{}\" auth=\"{}\" des=\"{}\">\n" +
                "        <lx-mod-items>\n" +
                "            <lx-item remark=\"\">\n" +
                "            </lx-item>\n" +
                "        </lx-mod-items>\n" +
                "    </lx-modifiy>\n" +
                "</root>";
        return StrUtil.format(ex,Optional.of(updXmlPanel.modifyNoField.getText()).orElse("")
                ,Optional.of(updXmlPanel.authorField.getText()).orElse("")
        ,Optional.of(updXmlPanel.modifyMsg.getText()).orElse(""));
    }

    @Override
    public String getSuffix() {
        return Optional.of(updXmlPanel.suffixField.getText()).orElse("");
    }

    @Override
    public Language getLanguage() {
        return Language.findLanguageByID("XML");
    }

    @Override
    public String getTabName() {
        return "upd模板文件";
    }

    @Override
    public Component getPanel() {
        return updXmlPanel;
    }

    @Override
    public Component newPanel() {
        LocalAdd localAdd = LocalAddDao.getCur();
        CommonSetting commonSetting = FileDao.getCommonSetting();
        updXmlPanel = new UpdXmlPanel(commonSetting,localAdd,"xml","-upd");
        return updXmlPanel;
    }
}
